package com.kakarote.admin.common;

import com.kakarote.core.entity.UserInfo;
import com.kakarote.core.feign.admin.entity.AdminMessageBO;
import com.kakarote.core.feign.admin.entity.AdminMessageEnum;
import com.kakarote.core.utils.UserUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * 手机端消息推送util
 *
 * @author zhangzhiwei
 * @date 2020年11月9日15:20:59
 */
@Slf4j
public class MobilePushUtil {

    public static String wxChatPushMessage(AdminMessageBO adminMessageBO) {
        String leftContent = getLeftContent(adminMessageBO);
        if ("".equals(leftContent)) {
            return "";
        }
        return leftContent + adminMessageBO.getTitle() + getRightContent(adminMessageBO);
    }

    public static String wxFlyDingChatPushMessage(AdminMessageBO adminMessageBO) {
        String leftContent = getLeftContent(adminMessageBO);
        if ("".equals(leftContent)) {
            return "";
        }
        return leftContent + adminMessageBO.getTitle() + getRightContent(adminMessageBO);
    }

    private static String getLeftContent(AdminMessageBO adminMessageBO) {
        AdminMessageEnum messageEnum = AdminMessageEnum.parse(adminMessageBO.getMessageType());
        UserInfo userInfo = UserUtil.getUser();
        String name;
        if (userInfo.isWxUser() || userInfo.isDingtalkUser()) {
            name = "$userName=" + userInfo.getRealname() + "$";
        } else {
            name = userInfo.getRealname();
        }

        switch (messageEnum) {
            case OA_TASK_ALLOCATION:
            case OA_TASK_OVER:
                return name + "将";
            case OA_TASK_JOIN:
            case OA_EVENT_MESSAGE:
                return name + "邀请您参与";
            case OA_LOG_REPLY:
                return name + "回复了您的";
            case OA_LOG_SEND:
                return name + "将日志";
            case OA_EXAMINE_REJECT:
            case CRM_CONTRACT_REJECT:
            case CRM_RECEIVABLES_REJECT:
                return name + "拒绝您的";
            case OA_EXAMINE_PASS:
                return name + "已经审核通过您的";
            case OA_NOTICE_MESSAGE:
                return "您有一个新公告";
            case CRM_CONTRACT_PASS:
                return name + "已经审核通过您的";
            case CRM_RECEIVABLES_PASS:
                return name + "已经审核通过您的";
            case CRM_BUSINESS_USER:
                return name + "将您添加为商机";
            case CRM_CUSTOMER_USER:
                return name + "将您添加为客户";
            case CRM_CONTRACT_USER:
                return name + "将您添加为合同";
            case OA_EXAMINE_NOTICE:
                return name + "提交了";
            case CRM_CONTRACT_EXAMINE:
                return name + "提交了";
            case CRM_RECEIVABLES_EXAMINE:
                return name + "提交了";
            case CRM_BUSINESS_TEAM_EXIT:
                return name + "退出了您商机";
            case CRM_CUSTOMER_TEAM_EXIT:
                return name + "退出了您客户";
            case CRM_CONTRACT_TEAM_EXIT:
                return name + "退出了您合同";
            case CRM_BUSINESS_REMOVE_TEAM:
                return name + "将您移出了商机";
            case CRM_CUSTOMER_REMOVE_TEAM:
                return name + "将您移出了客户";
            case CRM_CONTRACT_REMOVE_TEAM:
                return name + "将您移出了合同";
            case OA_COMMENT_REPLY:
                return name + "回复了您评论的日志";
            case CRM_INVOICE_REJECT:
                return name + "拒绝您的";
            case CRM_INVOICE_PASS:
                return name + "已经审核通过您的";
            case CRM_INVOICE_EXAMINE:
                return name + "提交了";
            case KM_DOCUMENT_SHARE_OPEN:
                return name + "将文档";
            case JXC_PURCHASE_EXAMINE:
                return name + "提交了";
            case JXC_PURCHASE_REJECT:
                return name + "拒绝您的";
            case JXC_PURCHASE_PASS:
                return name + "已经审核通过您的";
            case JXC_RETREAT_EXAMINE:
                return name + "提交了";
            case JXC_RETREAT_REJECT:
                return name + "拒绝您的";
            case JXC_RETREAT_PASS:
                return name + "已经审核通过您的";
            case JXC_SALE_EXAMINE:
                return name + "提交了";
            case JXC_SALE_REJECT:
                return name + "拒绝您的";
            case JXC_SALE_PASS:
                return name + "已经审核通过您的";
            case JXC_SALE_RETURN_EXAMINE:
                return name + "提交了";
            case JXC_SALE_RETURN_REJECT:
                return name + "拒绝您的";
            case JXC_SALE_RETURN_PASS:
                return name + "已经审核通过您的";
            case JXC_PAYMENT_EXAMINE:
                return name + "提交了";
            case JXC_PAYMENT_REJECT:
                return name + "拒绝您的";
            case JXC_PAYMENT_PASS:
                return name + "已经审核通过您的";
            case JXC_COLLECTION_EXAMINE:
                return name + "提交了";
            case JXC_COLLECTION_REJECT:
                return name + "拒绝您的";
            case JXC_COLLECTION_PASS:
                return name + "已经审核通过您的";
            case JXC_INVENTORY_EXAMINE:
                return name + "提交了";
            case JXC_INVENTORY_REJECT:
                return name + "拒绝您的";
            case JXC_INVENTORY_PASS:
                return name + "已经审核通过您的";
            case JXC_ALLOCATION_EXAMINE:
                return name + "提交了";
            case JXC_ALLOCATION_REJECT:
                return name + "拒绝您的";
            case JXC_ALLOCATION_PASS:
                return name + "已经审核通过您的";
            default:
                return "";
        }
    }

    private static String getRightContent(AdminMessageBO adminMessageBO) {
        AdminMessageEnum messageEnum = AdminMessageEnum.parse(adminMessageBO.getMessageType());
        switch (messageEnum) {
            case OA_TASK_ALLOCATION:
                return "任务分配给您，请及时查看";
            case OA_TASK_JOIN:
                return "任务，请及时查看";
            case OA_TASK_OVER:
                return "任务标记结束";
            case OA_LOG_REPLY:
                return "日志：" + adminMessageBO.getContent() + "，请及时查看";
            case OA_LOG_SEND:
                return "发送给您，请及时查看";
            case OA_EXAMINE_REJECT:
                return "，拒绝理由：" + adminMessageBO.getContent() + "，请及时处理";
            case OA_EXAMINE_PASS:
            case OA_NOTICE_MESSAGE:
                return "，请及时查看";
            case OA_EVENT_MESSAGE:
                return "的日程，请及时查看";
            case CRM_CONTRACT_REJECT:
                return "合同审批，拒绝理由：" + adminMessageBO.getContent() + "，请及时处理";
            case CRM_CONTRACT_PASS:
                return "合同，请及时查看";
            case CRM_RECEIVABLES_REJECT:
                return "回款审批，拒绝理由：" + adminMessageBO.getContent() + "，请及时处理";
            case CRM_RECEIVABLES_PASS:
                return "回款，请及时查看";
            case CRM_BUSINESS_USER:
            case CRM_CUSTOMER_USER:
            case CRM_CONTRACT_USER:
                return "的成员";
            case OA_EXAMINE_NOTICE:
                return "，请及时处理";
            case CRM_CONTRACT_EXAMINE:
                return "合同审批，请及时处理";
            case CRM_RECEIVABLES_EXAMINE:
                return "回款审批，请及时处理";
            case CRM_BUSINESS_TEAM_EXIT:
            case CRM_CUSTOMER_TEAM_EXIT:
            case CRM_CONTRACT_TEAM_EXIT:
            case CRM_BUSINESS_REMOVE_TEAM:
            case CRM_CUSTOMER_REMOVE_TEAM:
            case CRM_CONTRACT_REMOVE_TEAM:
                return "的团队";
            case OA_COMMENT_REPLY:
                return "：" + adminMessageBO.getContent() + "，请及时查看";
            case CRM_INVOICE_REJECT:
                return "，拒绝理由：" + adminMessageBO.getContent() + "，请及时处理";
            case CRM_INVOICE_PASS:
                return "发票，请及时查看";
            case CRM_INVOICE_EXAMINE:
                return "发票审批，请及时处理";
            case KM_DOCUMENT_SHARE_OPEN:
                return "分享给您，请及时查看";
            case JXC_PURCHASE_EXAMINE:
                return "采购订单审批，请及时处理";
            case JXC_PURCHASE_REJECT:
                return "采购订单审批，拒绝理由：" + adminMessageBO.getContent() + "，请及时处理";
            case JXC_PURCHASE_PASS:
                return "采购订单，请及时查看";
            case JXC_RETREAT_EXAMINE:
                return "采购退货单审批，请及时处理";
            case JXC_RETREAT_REJECT:
                return "采购退货单审批，拒绝理由：" + adminMessageBO.getContent() + "，请及时处理";
            case JXC_RETREAT_PASS:
                return "采购退货单，请及时查看";
            case JXC_SALE_EXAMINE:
                return "销售订单审批，请及时处理";
            case JXC_SALE_REJECT:
                return "销售订单审批，拒绝理由：" + adminMessageBO.getContent() + "，请及时处理";
            case JXC_SALE_PASS:
                return "销售订单，请及时查看";
            case JXC_SALE_RETURN_EXAMINE:
                return "销售退货单审批，请及时处理";
            case JXC_SALE_RETURN_REJECT:
                return "销售退货单审批，拒绝理由：" + adminMessageBO.getContent() + "，请及时处理";
            case JXC_SALE_RETURN_PASS:
                return "销售退货单，请及时查看";
            case JXC_PAYMENT_EXAMINE:
                return "付款单审批，请及时处理";
            case JXC_PAYMENT_REJECT:
                return "付款单审批，拒绝理由：" + adminMessageBO.getContent() + "，请及时处理";
            case JXC_PAYMENT_PASS:
                return "付款单，请及时查看";
            case JXC_COLLECTION_EXAMINE:
                return "回款单审批，请及时处理";
            case JXC_COLLECTION_REJECT:
                return "回款单审批，拒绝理由：" + adminMessageBO.getContent() + "，请及时处理";
            case JXC_COLLECTION_PASS:
                return "回款单，请及时查看";
            case JXC_INVENTORY_EXAMINE:
                return "盘点审批，请及时处理";
            case JXC_INVENTORY_REJECT:
                return "盘点审批，拒绝理由：" + adminMessageBO.getContent() + "，请及时处理";
            case JXC_INVENTORY_PASS:
                return "盘点，请及时查看";
            case JXC_ALLOCATION_EXAMINE:
                return "调拨审批，请及时处理";
            case JXC_ALLOCATION_REJECT:
                return "调拨审批，拒绝理由：" + adminMessageBO.getContent() + "，请及时处理";
            case JXC_ALLOCATION_PASS:
                return "调拨，请及时查看";
            default:
                return "";
        }
    }

//    private static PushPayload buildPushObject(String title, List<String> alias) {
//        return PushPayload.newBuilder()
//                .setPlatform(Platform.android_ios())
//                .setAudience(Audience.alias(alias))
//                .setNotification(Notification.newBuilder()
//                        .addPlatformNotification(AndroidNotification.newBuilder()
//                                .setAlert(title)
//                                .build())
//                        .addPlatformNotification(IosNotification.newBuilder()
//                                .incrBadge(1)
//                                .setAlert(title)
//                                .build())
//                        .build())
//                .setOptions(Options.newBuilder().setApnsProduction(true).build())
//                .build();
//    }
}
